<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script text="javascript">
        // 1.
        // var str1 = 'str';
        // str1 += 2;
        // var obj = typeof str1;  //obj = string
        // if (typeof obj == 'string') {
        //     var obj = new String()
        //     obj.sign = 'Live'
        // }
        // console.log(obj.sign);



// 2.算出字符串的所占用字节的长度， 如: str  ='live' 长度为4      str='live生活'   长度为8 （提示:unicode<=255的占1字节，unicode>255的占用2字节, str.charCodeAt(i)查看i的字节码）
            // var a = 'hello 间时'
            // function b(a){
            //     var num = a.length
            //     for (let i = 0; i < a.length; i++) {
            //        if (a.charCodeAt(i)>255) {
            //            num++;
            //        }
            //     }
            //     return num
            // } console.log(b(a))

// 3.要求输入一串低于10位的数字，输出对应的中文大写:
// 例： input: 10001  --> 一万零一     ；   input:  10,000,000  -->  一千万
function a(num) {
    var arr1 = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
    var arr2 = ['', '十', '百', '千', '万', '十', '百', '千', '亿', '十', '百', '千','万', '十', '百', '千','亿'];//可继续追加更高位转换值
    if(!num || isNaN(num)){
        return "零";
    }
    var english = num.toString().split("")
    var result = "";
    for (var i = 0; i < english.length; i++) {
        var des_i = english.length - 1 - i;
        result = arr2[i] + result;
        var arr1_index = english[des_i];
        result = arr1[arr1_index] + result;
    }
    result = result.replace(/零(千|百|十)/g, '零').replace(/十零/g, '十');
    result = result.replace(/零+/g, '零');
    result = result.replace(/零亿/g, '亿').replace(/零万/g, '万');
    result = result.replace(/亿万/g, '亿');
    result = result.replace(/零+$/, '')
    result = result.replace(/^一十/g, '十');
    return result;
}
console.log(a(666));
    </script>
</body>
</html>